<?php

class DBMRelationship {
	/** Relationship types */
	const TYPE_ONE_TO_ONE = 0;
	const TYPE_ONE_TO_MANY = 1;

	/**
	 * The relationship type
	 *
	 * @var int
	 */
	private $type;
	
	/**
	 * The target entity of this relation
	 *
	 * @var string
	 */
	private $targetEntity;
	
	/**
	 * The source entity of this relation
	 *
	 * @var string
	 */
	private $sourceEntity;
	
	/**
	 * The attribute that will receive the relationship data
	 *
	 * @var string
	 */
	private $attribute;
	
	/**
	 * The connection attributes
	 *
	 * @var array(DBMConnection)
	 */
	private $connections;
	
	/**
	 * Return the relationship type
	 *
	 * @return int
	 */
	public function getType(){
		return $this->type;
	}
	
	/**
	 * Set the relationship type
	 *
	 * @param int $type
	 */
	public function setType($type){
		$this->type = $type;
	}
	
	/**
	 * Return the target entity
	 *
	 * @return string The entity
	 */
	public function getTargetEntity(){
		return $this->targetEntity;
	}
	
	/**
	 * Set the target entity
	 *
	 * @param string $targetEntity The entity
	 */
	public function setTargetEntity($targetEntity){ 
		$this->targetEntity = $targetEntity; 
	}
	
	/**
	 * Return the source entity
	 *
	 * @return string The source entity
	 */
	public function getSourceEntity(){
		return $this->sourceEntity;
	}
	
	/**
	 * Set the source entity
	 *
	 * @param string $targetEntity The source entity
	 */
	public function setSourceEntity($sourceEntity){ 
		$this->sourceEntity = $sourceEntity;
	}

	/**
	 * Return the attribute wich will receive the relationship data
	 *
	 * @return string
	 */
	public function getAttribute(){
		return $this->attribute;
	}
	
	/**
	 * Set the attribute wich will receive the relationship data
	 *
	 * @param string $attribute
	 */
	public function setAttribute($attribute){
		$this->attribute = $attribute;
	}
	
	/**
	 * Return the connections
	 *
	 * @return array(DBMConnection)
	 */
	public function getConnections(){
		return $this->connections;
	}
	
	/**
	 * Set the connections
	 *
 	 * @param array<DBMConnection> $connections
	 */
	public function setConnections($connections){
		if(is_array($connections)){
			$this->connections = $connections;
		}
	}
	
	/**
	 * Add a connection to this relationship
	 *
	 * @param DBMConnection $connection
	 */
	public function addConnection($sourceAttribute, $targetAttribute){
		// create a new connection
		$connection = new DBMRelationshipConnection();
		
		// set the data
		$connection->setSourceAttribute($sourceAttribute);
		$connection->setTargetAttribute($targetAttribute);
		
		// store
		$this->connections[] = $connection;
	}
}

?>